//
//  ZRTabBarController.m
//  iKanMovie
//
//  Created by qianfeng on 15/11/3.
//  Copyright (c) 2015年 van7ish Studio. All rights reserved.
//

#import "ZRTabBarController.h"

@interface ZRTabBarController ()
@property (nonatomic, weak) UIButton *selectedBtn;

@end

@implementation ZRTabBarController
- (void)ZRTabBar{

    self.customBar = [[UIImageView alloc] init];
    CGSize size = [UIScreen mainScreen].bounds.size;

    //self.customBar.frame = self.tabBar.bounds;
    self.customBar.frame = CGRectMake(0, self.view.frame.size.height - 49, self.view.frame.size.width, 49);
    self.customBar.backgroundColor = COLOR_LIGHTBGCOLOR;
    //[self.tabBar addSubview:self.customBar];
    
    self.tabBar.hidden = YES;
    self.customBar.userInteractionEnabled = YES;
    [self.view addSubview:self.customBar];
    
    NSArray *deSelectedArr = @[@"首页-d", @"云阅读-d", @"xianyutese_d", @"tuiguangziyuan_d", @"gerenzhognxin_d"];
    NSArray *selectedArr = @[@"首页-s", @"云阅读-s", @"xianyutese_s", @"tuiguangziyuan_s", @"gerenzhognxin_s"];
    for (int i = 0; i < deSelectedArr.count; i++) {
        UIButton *btn = [[UIButton alloc] init];
        btn.frame = CGRectMake(i * size.width / deSelectedArr.count, 6, size.width / deSelectedArr.count, 37);
        [btn setImage:[UIImage imageNamed:deSelectedArr[i]] forState:UIControlStateNormal];
         [btn setImage:[UIImage imageNamed:selectedArr[i]] forState:UIControlStateSelected];
        

        [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchDown];
        btn.tag = i + 1;
        [self.customBar addSubview:btn];
        if (i == 0) {
            [self btnClicked:btn];
        }
    }
    
    UIView *grayLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 0.5)];
    grayLine.backgroundColor = COLOR_GRAYLINE;
    [self.customBar addSubview:grayLine];
    
    self.customBar.userInteractionEnabled = YES;
}

- (void)btnClicked:(UIButton *)button{

    self.selectedBtn.selected = NO;
    button.selected = YES;
    self.selectedBtn = button;
    self.selectedIndex = button.tag - 1;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self ZRTabBar];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
